﻿using NHibernate;
using NHibernate.Criterion;
using System.Collections.Generic;
using MSP.Data.Domain;
using MSP.Data.NHibernate;

namespace MSP.Data.Repositories
{
    public class ProductCategoryRepository : Repository<ProductCategory>
    {
        public ProductCategoryRepository(ISession session)
            : base(session)
        {
        }

        public void SaveProductCategory(ProductCategory productCategory)
        {
            Add(productCategory);
        }

        public void UpdateProductCategory(ProductCategory productCategory)
        {
            Update(productCategory);
        }

        public void DeleteProductCategory(int Id)
        {
            ProductCategory productCategory = GetProductCategoryById(Id);
            if (productCategory != null)
                Delete(productCategory);
        }

        public ProductCategory GetProductCategoryById(int Id)
        {
            return Session.CreateCriteria<ProductCategory>()
                          .Add(Restrictions.Eq("Id", Id))
                          .UniqueResult<ProductCategory>();
        }

        public IList<ProductCategory> GetAllProductCategory()
        {
            return (Session.CreateCriteria<ProductCategory>()
               .List<ProductCategory>() as List<ProductCategory>);
        }
    }
}
